package com.blockmeta.bbs.immodule.activity;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.view.View;

import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.activity.base.BaseIMSearchActivity;
import com.blockmeta.bbs.immodule.bean.IMSearchNormalPOJO;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author airthor
 * @date 2020/5/13
 * im搜索文章快讯等搜索结果返回页面
 */
public class IMSearchOtherResultActivity extends BaseIMSearchActivity{
    /**
     * 用来标志搜索的是文章0 快讯1 行情2 活动3
     */
    private int mSearchType;
    public static final int NEWS = 0;
    public static final int FAST = 1;
    public static final int MARKET = 2;
    public static final int POST = 3;

    @Override
    protected void initialize() {
        super.initialize();
        mSearchType = getIntent().getIntExtra(Constant.ZERO,NEWS);
        mEdtSearchInput.setHint(getSearchTitle(mSearchType));
        setTitleText(getSearchTitle(mSearchType));
        mRcvSearchList.setVisibility(View.GONE);
        mFragmentContainer.setVisibility(View.VISIBLE);
    }

    private String getSearchTitle(int searchType) {
        switch (searchType){
            case NEWS:
                return "搜索文章";
            case FAST:
                return "搜索快讯";
            case MARKET:
                return "搜索行情";
            case POST:
                return "搜索帖子";
            default:
                return "搜索";
        }
    }

    @Override
    protected BaseQuickAdapter<IMSearchNormalPOJO, BaseViewHolder> getAdapter() {
        return null;
    }

    @Override
    protected void searchOnNet(String content) {
        mTvSearchResult.setVisibility(View.VISIBLE);
        mGroupGoSearch.setVisibility(View.GONE);
        FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
        Fragment fragment = getFragment(content);
        transaction.replace(R.id.fl_container,fragment);
        transaction.commitAllowingStateLoss();
    }

    private Fragment getFragment(String content) {
        switch (mSearchType){
            case NEWS:
                return (Fragment) RouterHelper.buildPath(RouterPath.INFOR_LIST_FRAGMENT)
                        .withString(Constant.ZERO,"keyword")
                        .withString(Constant.ONE,content)
                        .withBoolean(Constant.THREE,true)
                        .navigation();
            case FAST:
                return (Fragment) RouterHelper.buildPath(RouterPath.FAST_SEARCH_NEWS_FRAGMENT)
                        .withString(Constant.ZERO,"keyword")
                        .withString(Constant.ONE,content)
                        .withBoolean(Constant.THREE,true)
                        .navigation();
            case MARKET:
                return (Fragment) RouterHelper.buildPath(RouterPath.SEARCH_COINS_RESULT_FRAGMENT)
                        .withString(Constant.ZERO,content)
                        .withString(Constant.ONE,content)
                        .withBoolean(Constant.THREE,true)
                        .navigation();
            case POST:
                return (Fragment) RouterHelper.buildPath(RouterPath.BBS_LIST_FRAGMENT)
                        .withString(Constant.ZERO,"keyword")
                        .withString(Constant.ONE,content)
                        .withBoolean(Constant.THREE,true)
                        .navigation();
            default:
                return (Fragment) RouterHelper.buildPath(RouterPath.INFOR_LIST_FRAGMENT)
                        .withString(Constant.ZERO,"keyword")
                        .withString(Constant.ONE,content)
                        .withBoolean(Constant.THREE,true)
                        .navigation();
        }
    }

    @Override
    protected View setEmptyView() {
        return null;
    }


}
